/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


import Qt 4.7
import "../script/script.js" as Script

Item {
    id:turnOverView

    property variant model: null
    //property url delegateImageSource: ""
    property  int itemWidth: width*170/640
    property  int itemHeight: itemWidth*130/170
    signal itemClicked(int index)

    width: 640; height: 360
    //opacity: 1.0


    Component {
        id: myDelegate

        Item{
            property int rotateY: PathView.rotateY
            id:oneItem
            width: turnOverView.itemWidth
            height: turnOverView.itemHeight
            visible: PathView.onPath
            z: PathView.zOrder


            Image{
                id:myImage
                width: parent.width
                height: parent.height
                source: indexImage //Script.sysQmlItemPath(indexImage)
                anchors.horizontalCenter: parent.horizontalCenter
                smooth: true
            }
            Image {
                id: subImage
                width: parent.width
                height: parent.height
                source: indexImage //Script.sysQmlItemPath(indexImage)
                anchors.horizontalCenter: parent.horizontalCenter
                smooth: true
                transform: Rotation { origin.x: 0; origin.y: subImage.height; axis { x: 1; y: 0; z: 0 } angle: 180 }
            }
            Rectangle{
                y: myImage.height;
                x: -1
                width: myImage.width +2
                height: myImage.height + 2
                gradient: Gradient {
                    GradientStop { position: 0.0; color: Qt.rgba(0,0,0,0.6) }
                    GradientStop { position: 0.4; color: Qt.rgba(0,0,0,1.0) }
                }
                //opacity: 0.7
                smooth: true
            }

            transform:[
                Rotation{
                    angle: rotateY
                    origin.x: myImage.width/2
                    origin.y: myImage.height/2
                    axis { x: 0; y: 1; z: 0 }
                },
                Scale {
                    xScale:PathView.scalePic; yScale:PathView.scalePic
                    origin.x: myImage.width/2;   origin.y: myImage.height/2
                }
            ]

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    if(myView.currentIndex == index) {
                        console.log("cliked");
                        turnOverView.itemClicked(index);
                    }

                }
            }

        }//Item
    }

    PathView {
        id: myView
        focus: true
        model: turnOverView.model
        delegate: myDelegate
        anchors.fill: parent
        pathItemCount: 9

        preferredHighlightBegin: 0.5
        preferredHighlightEnd: 0.5
        highlightRangeMode: PathView.StrictlyEnforceRange
        highlightMoveDuration: 100

        flickDeceleration: 390
        path: myPath
        clip: false
    }

    Path {
        id: myPath
        startX: itemWidth/2 + 20; startY: turnOverView.itemHeight/2 + 20
        PathAttribute {name: "rotateY"; value: 70.0}
        PathAttribute {name: "scalePic"; value: 1.0}
        PathAttribute {name: "zOrder"; value: 1}

        PathLine{x:turnOverView.width/2 - itemWidth/2; y: turnOverView.itemHeight/2 + 20}
        PathPercent {value: 0.40}
        PathAttribute {name: "rotateY"; value: 70.0}
        PathAttribute {name: "scalePic"; value: 1.0}
        PathAttribute {name: "zOrder"; value: 5}


        PathLine{x:turnOverView.width/2; y:turnOverView.itemHeight/2 + 20}
        PathPercent {value: 0.50}
        PathAttribute {name: "rotateY"; value: 0.0}
        PathAttribute {name: "scalePic"; value: 1.1}
        PathAttribute {name: "zOrder"; value: 10}


        PathLine{x:turnOverView.width/2 + itemWidth/2; y:turnOverView.itemHeight/2 + 20}
        PathPercent {value: 0.60}
        PathAttribute {name: "rotateY"; value: -70.0}
        PathAttribute {name: "scalePic"; value: 1.0}
        PathAttribute {name: "zOrder"; value: 5}


        PathLine{x:width- itemWidth/2 - 20; y: turnOverView.itemHeight/2 + 20}
        PathPercent {value: 1.00}
        PathAttribute {name: "rotateY"; value: -70.0}
        PathAttribute {name: "scalePic"; value: 1.0}
        PathAttribute {name: "zOrder"; value: 1}
    }
}
